﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace KhachSan.Process.Private.Bo.Class
{
    class MarqueeLabel : LabelControl
    {
        private int CurrentPosition { get; set; }
        private Timer timer;

        public Timer Timer
        {
            get { return timer; }
            set { timer = value; }
        }
        private bool leftToRight = true;

        public bool LeftToRight
        {
            get { return leftToRight; }
            set { leftToRight = value; }
        }
        public MarqueeLabel()
        {
            //UseCompatibleTextRendering = true;
            timer = new Timer();
            timer.Interval = 30;
            timer.Tick += new EventHandler(Timer_Tick);
            timer.Start();
        }

        void Timer_Tick(object sender, EventArgs e)
        {
            try
            {
                if (this.leftToRight == true)
                {
                    if (CurrentPosition > Width)
                        CurrentPosition = -Width;
                    else
                        CurrentPosition += 2;
                }
                else
                {
                    if (CurrentPosition + Text.Length < 0)
                        CurrentPosition = Width;
                    else
                        CurrentPosition -= 2;
                }
                Invalidate();
            }
            catch { }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.TranslateTransform((float)CurrentPosition, 0);
            base.OnPaint(e);
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (timer != null)
                    timer.Dispose();
            }
            timer = null;
        }
    }


}
